package com.ruoyi.football.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.football.domain.StadiumDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.football.mapper.StadiumMapper;
import com.ruoyi.football.domain.Stadium;
import com.ruoyi.football.service.IStadiumService;

import javax.annotation.Resource;

/**
 * 球场Service业务层处理
 * 
 * @author lyx
 * @date 2024-12-08
 */
@Service
public class StadiumServiceImpl implements IStadiumService 
{
    @Resource
    private StadiumMapper stadiumMapper;

    @Resource
    private StadiumDetailServiceImpl stadiumDetailService;

    /**
     * 查询球场
     * 
     * @param id 球场主键
     * @return 球场
     */
    @Override
    public Stadium selectStadiumById(Long id)
    {
        return stadiumMapper.selectStadiumById(id);
    }

    /**
     * 查询球场列表
     * 
     * @param stadium 球场
     * @return 球场
     */
    @Override
    public List<Stadium> selectStadiumList(Stadium stadium)
    {
        List<Stadium> list = stadiumMapper.selectStadiumList(stadium);
//        查出球场场地
        for (Stadium stadium1 : list) {
            LambdaQueryWrapper<StadiumDetail> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(StadiumDetail::getStadiumId,stadium1.getId());
            List<StadiumDetail> details = stadiumDetailService.list(queryWrapper);
            stadium1.setStadiumDetailList(details);
        }
        return list;
    }

    /**
     * 新增球场
     * 
     * @param stadium 球场
     * @return 结果
     */
    @Override
    public int insertStadium(Stadium stadium)
    {
        return stadiumMapper.insertStadium(stadium);
    }

    /**
     * 修改球场
     * 
     * @param stadium 球场
     * @return 结果
     */
    @Override
    public int updateStadium(Stadium stadium)
    {
        return stadiumMapper.updateStadium(stadium);
    }

    /**
     * 批量删除球场
     * 
     * @param ids 需要删除的球场主键
     * @return 结果
     */
    @Override
    public int deleteStadiumByIds(Long[] ids)
    {
        return stadiumMapper.deleteStadiumByIds(ids);
    }

    /**
     * 删除球场信息
     * 
     * @param id 球场主键
     * @return 结果
     */
    @Override
    public int deleteStadiumById(Long id)
    {
        return stadiumMapper.deleteStadiumById(id);
    }
}
